package com.unicloud.medical.aliyun.starter;

import com.aliyun.oss.OSS;
import com.unicloud.medical.oss.common.model.OSSServerProperties;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;

@Slf4j
@Setter
@NoArgsConstructor
public class AliyunHealthCheckStarter implements ApplicationRunner {

    private OSS ossClient;
    private OSSServerProperties.Check check;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        if (!check.isEnable() || StringUtils.isEmpty(check.getBucketName())) return;
        try {
            ossClient.doesBucketExist(check.getBucketName());
        } catch (Exception e) {
            log.error("aliyun客户端启动失败，请检查服务配置是否可用 cause={}", e.getMessage());
        }
    }
}
